package ai.people.netmon.warning.dict;

import ai.people.core.grpc.lib.dict.DictRequest;
import ai.people.core.grpc.lib.dict.DictResponse;
import ai.people.core.grpc.lib.dict.DictResponseData;
import ai.people.core.grpc.lib.dict.DictServiceGrpc;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author yuanqinglong
 * @date 2022/8/11 18:57
 */
@Component
public class DictGrpcClient {


    @GrpcClient(value = "NM-SERVICE-SYSTEM")
    private DictServiceGrpc.DictServiceBlockingStub dictServiceBlockingStub;


    /**
     * 得到dict地图
     *
     * @param type 类型
     * @return {@link Map}<{@link String}, {@link String}>
     */
    public Map<String, String> getDictMap(String type){
        DictResponse dictResponse = dictServiceBlockingStub.dictList(DictRequest.newBuilder().setDictType(type).build());
        return dictResponse.getListList().stream().collect(Collectors.toMap(DictResponseData::getDictDataValue, DictResponseData::getDictDataName));
    }
}
